package com.starsea.book.ui.newpage.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.starsea.book.databinding.ItemBookCityCenterChildBinding
import com.starsea.book.ui.newpage.entity.BookInfoEntity
import com.starsea.book.ui.newpage.utils.loadNormalImage
import com.starsea.book.ui.newpage.utils.visibleOrGone

/**
 * @author Lee
 * @createTime 2024-07-12 20 GMT+8
 * @desc :
 */
class BookCityCenterChildAdapter(var mContext: Context) :
  BaseQuickAdapter<BookInfoEntity, BookCityCenterChildAdapter.MyViewHolder>() {

  override fun onBindViewHolder(holder: MyViewHolder, position: Int, item: BookInfoEntity?) {

    holder.binding.ivCover.loadNormalImage(mContext, item!!.bookCover?:"")
    holder.binding.tvBookTitle.text = item.bookTitle
    holder.binding.tvType.text = if (item.bookState == 0) "连载"
    else if (item.bookState == 1) "完结"
    else "停更"

    holder.binding.rtvVipTag.visibleOrGone(item.isVipBook == 1)

  }

  override fun onCreateViewHolder(
    context: Context,
    parent: ViewGroup,
    viewType: Int,
  ): MyViewHolder {
    return MyViewHolder(parent = parent)
  }

  class MyViewHolder(
    parent: ViewGroup,
    val binding: ItemBookCityCenterChildBinding = ItemBookCityCenterChildBinding.inflate(
      LayoutInflater.from(parent.context), parent, false
    ),
  ) : RecyclerView.ViewHolder(binding.root)

}